<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('仓库详情')"/>
    <th:block th:include="include :: layout-latest-css"/>
    <th:block th:include="include :: ztree-css"/>
</head>
<body class="gray-bg">
<div class="ui-layout-center">
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="user-form">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>物资编码：</label><input type="text" name="productId"/>
                            </li>

                            <li>
                                <label>物品名称：</label><input type="text" name="productName"/>
                            </li>
                            <li>
                                <label>物料类型：</label>

                                <input autocomplete="off" name="productClassification" style="width:100px"
                                       onclick="selectProductTypeTree()" id="treeName" type="text"
                                       placeholder="请选择物料类型" class="form-control" >
                                <input id="treeId" name="parentId" hidden>
                            </li>

                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
            </div>

            <div id="div" class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
</div>

<th:block th:include="include :: footer"/>
<th:block th:include="include :: layout-latest-js"/>

<th:block th:include="include :: ztree-js"/>
<script th:inline="javascript">
    var editFlags = [[${@permission.hasPermi('system:item')}]];
    var editFlag = [[${@permission.hasPermi('system:item:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:user:remove')}]];
    var editsFlag = [[${@permission.hasPermi('bas:warehouse:edits')}]];
    var useableDatas = [[${@dict.getType('yes_or_no')}]];
    var prefix = ctx + "bas/product";

    //页面加载完成后执行
    $(function () {
        var panehHidden = false;
        console.log($(this).width())
        if ($(this).width() < 801) {
            panehHidden = true;
        }
        $('body').layout({initClosed: panehHidden, west__size: 185});
        // 回到顶部绑定
        if ($.fn.toTop !== undefined) {
            var opt = {
                win: $('.ui-layout-center'),
                doc: $('.ui-layout-center')
            };
            $('#scroll-up').toTop(opt);
        }
        queryUserList();
    });

    function queryUserList() {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            height: $("#div").height() / 1,
            clickToSelect: true,
            // exportUrl: prefix + "/export",
            // importUrl: prefix + "/importData",
            // importTemplateUrl: prefix + "/importTemplate",
            pageSize: 10,
            pageList: [10, 25, 50],
            sortName: "productId",
            sortOrder: "desc",
            modalName: "项目",
            columns: [
                {
                    halign: 'center',
                    align: 'center',
                    checkbox: true
                },
                {
                    title: "序号",
                    halign: 'center',
                    align: 'center',
                    width: 55,
                    visible: false,
                    formatter: function (value, row, index) {
                        //获取每页显示的数量
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
                        //获取当前是第几页
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
                        //返回序号，注意index是从0开始的，所以要加上1
                        return pageSize * (pageNumber - 1) + index + 1;

                    }
                },
                {
                    field: 'productGuid',
                    title: '主键',
                    halign: 'center',
                    align: 'center',
                    sortable: true,
                    visible: false
                },
                {
                    field: 'productId',
                    title: '物资编码',
                    halign: 'center',
                    align: 'center',

                    visible: true
                },
                {
                    field: 'productName',
                    title: '物资名称',
                    halign: 'center',
                    align: 'center',

                    visible: true
                },
                {
                    field: 'model',
                    title: '规格',
                    halign: 'center',
                    align: 'center',
                    visible: true
                },
                {
                    field: 'productsUsingFinished',
                    title: '是否可用',
                    halign: 'center',
                    align: 'center',

                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(useableDatas, value);
                    },
                    visible: true
                },
                {
                    field: 'productUnit',
                    title: '单位',
                    halign: 'center',
                    align: 'center',

                    visible: true
                },
                {
                    field: 'remark',
                    title: '备注',
                    halign: 'center',
                    align: 'center',

                    visible: true
                },
                ]
        };
        $.table.init(options);
    }

    function selectProductTypeTree() {
        var productTypeNo = $.common.isEmpty($("#treeId").val()) ? "1" : $("#treeId").val();
        var url = ctx + "bas/basProducttype/selectBasProducttypeTree/"+productTypeNo;
        var options = {
            title: '选择物料分类',
            width: "380",
            url: url,
            callBack: doSubmitTree
        };
        $.modal.openOptions(options);
    }
    function doSubmitTree(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        var body = layer.getChildFrame('body', index);
        // var body = layero.find("iframe")[1].$._tree.zOnClick();
        $("#treeId").val(body.find('#treeId').val());
        $("#treeName").val(body.find('#treeName').val());
        console.log(body.find('#treeId').val())
        console.log(body.find('#treeName').val())
        layer.close(index);
    }


    function submitHandler() {
        var row = $("#bootstrap-table").bootstrapTable('getSelections');
        return row;
    }
</script>
</body>
<!-- 导入区域 -->
<script id="importTpl" type="text/template">
    <form enctype="multipart/form-data" class="mt20 mb10">
        <div class="col-xs-offset-1">
            <input type="file" id="file" name="file"/>
            <div class="mt10 pt5">
                <input type="checkbox" id="updateSupport" name="updateSupport" title="如果登录账户已经存在，更新这条数据。"> 是否更新已经存在的用户数据
                &nbsp; <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i
                    class="fa fa-file-excel-o"></i> 下载模板</a>
            </div>
            <font color="red" class="pull-left mt10">
                提示：仅允许导入“xls”或“xlsx”格式文件！
            </font>
        </div>
    </form>
</script>
</html>